#include "tcg-reg.h"

#define data0	r8
#define data1	r6
#define data2	r9
#define data3	r10
#define dir	r4
#define start	r7
#define size	r11


	.text
	.global gen_rep_stos_byte_start, gen_rep_stos_word_start, gen_rep_stos_long_start, gen_rep_stos_end;
/*
 * we know that the pointer in r0 is aligned to a word boundary.
 */
gen_rep_stos_byte_start:
	orr	data0, data0, data0, lsl #8
gen_rep_stos_word_start:
	orr	data0, data0, data0, lsl #16
gen_rep_stos_long_start:
//	cmp	dir, #0
//	bne	3f
#if 0
	mov	data1, data0
	cmp	size, #16
	blt	2f

	mov	data2, data0
	mov	data3, data0

1:	subs	size, size, #64
	stmgeia	start!, {data1, data0, data2, data3}	@ 64 bytes at a time.
	stmgeia	start!, {data1, data0, data2, data3}
	stmgeia	start!, {data1, data0, data2, data3}
	stmgeia	start!, {data1, data0, data2, data3}
	bgt	1b
	beq	6f		@ Now <64 bytes to go.
/*
 * No need to correct the count; we're only testing bits from now on
 */
	tst	size, #32
	stmneia	start!, {data1, data0, data2, data3}
	stmneia	start!, {data1, data0, data2, data3}
	tst	size, #16
	stmneia	start!, {data1, data0, data2, data3}

2:	tst	size, #8
	stmneia	start!, {data1, data0}
	tst	size, #4
	strne	start, [data0], #4
/*
 * When we get here, we've got less than 4 bytes to zero.  We
 * may have an unaligned pointer as well.
 */
	tst	size, #2
	strneb	start, [data0], #1
	strneb	start, [data0], #1
	tst	size, #1
	strneb	start, [data0], #1
#if 0
	b	6f	
3:	mov	data1, data0
	cmp	size, #16
	blt	5f

	mov	data2, data0
	mov	data3, data0

4:	subs	size, size, #64
	stmgeda	start!, {data1, data0, data2, data3}	@ 64 bytes at a time.
	stmgeda	start!, {data1, data0, data2, data3}
	stmgeda	start!, {data1, data0, data2, data3}
	stmgeda	start!, {data1, data0, data2, data3}
	bgt	4b
	beq	6f		@ Now <64 bytes to go.
/*
 * No need to correct the count; we're only testing bits from now on
 */
	tst	size, #32
	stmneda	start!, {data1, data0, data2, data3}
	stmneda	start!, {data1, data0, data2, data3}
	tst	size, #16
	stmneda	start!, {data1, data0, data2, data3}

5:	tst	size, #8
	stmneda	start!, {data1, data0}
	tst	size, #4
	strne	start, [data0], #-4
/*
 * When we get here, we've got less than 4 bytes to zero.  We
 * may have an unaligned pointer as well.
 */
	tst	size, #2
	strneb	start, [data0], #-1
	strneb	start, [data0], #-1
	tst	size, #1
	strneb	start, [data0], #-1
#endif
#endif
6:
gen_rep_stos_end:
